/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

import com.click.app.Functions;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 *
 * @author ronald
 */
@Entity
@Table(name = "process_dressmakers")
@NamedQueries({@NamedQuery(name = "ProcessDressmaker.findAll", query = "SELECT pdm FROM ProcessDressmaker pdm")})

public class ProcessDressmaker extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;
    private Date initDate;
    private Date endDate;
    private Employee employee;
    private List<PantDetail> pantDetails = new ArrayList<PantDetail>();

    private Double totalAmountFail;
    private Double totalAmount;
    private Double totalCurrentAmount;
    private BalanceEmployee balanceEmployee;

    private List<ProcessDressmakerPurchaseDetail> listProcessDressmakerPurchaseDetail  = new ArrayList<ProcessDressmakerPurchaseDetail>();

    private Boolean deleted;
    
    public ProcessDressmaker(){}

    public  ProcessDressmaker(Long i, Date iD, Double tA, Double tAFail, Double tCA, Date eD){
        id = i;
        initDate = iD;
        totalAmount = Functions.getDouble3Decimal(tA);
        totalAmountFail = Functions.getDouble3Decimal(tAFail);
        totalCurrentAmount = Functions.getDouble3Decimal(tCA);
        endDate = eD;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "end_date" )
    public Date getEndDate() { 
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Basic(optional = false)
    @Column(unique=true, name = "id_process_dressmaker")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "init_date")
    public Date getInitDate() {
        return initDate;
    }

    public void setInitDate(Date initDate) {
        this.initDate = initDate;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE)
                .append(this.id).append(this.initDate)
                .append(this.endDate).toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ProcessDressmaker other = (ProcessDressmaker) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.initDate != other.initDate && (this.initDate == null || !this.initDate.equals(other.initDate))) {
            return false;
        }
        if (this.endDate != other.endDate && (this.endDate == null || !this.endDate.equals(other.endDate))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 53 * hash + (this.initDate != null ? this.initDate.hashCode() : 0);
        hash = 53 * hash + (this.endDate != null ? this.endDate.hashCode() : 0);
        return hash;
    }

    @JoinColumn(name = "id_employee", referencedColumnName = "id_user")
    @ManyToOne(optional = false)
    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "processDressmaker")
    public List<PantDetail> getPantDetails() {
        return pantDetails;
    }

    public void setPantDetails(List<PantDetail> pantDetails) {
        this.pantDetails = pantDetails;
    }

    @OneToOne(mappedBy = "processDressmaker")
    public BalanceEmployee getBalanceEmployee() {
        return balanceEmployee;
    }

    public void setBalanceEmployee(BalanceEmployee balanceEmployee) {
        this.balanceEmployee = balanceEmployee;
    }

    @Column(name = "total_amount", length=3)
    public Double getTotalAmount() {
        return Functions.getDouble3Decimal(totalAmount);
    }

    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = Functions.getDouble3Decimal(totalAmount);
    }

    @Column(name = "total_amount_fail")
    public Double getTotalAmountFail() {
        return Functions.getDouble3Decimal(totalAmountFail);
    }

    public void setTotalAmountFail(Double totalAmountFail) {
        this.totalAmountFail = Functions.getDouble3Decimal(totalAmountFail);
    }

    @Column(name = "total_current_amount")
    public Double getTotalCurrentAmount() {
        return Functions.getDouble3Decimal(totalCurrentAmount);
    }

    public void setTotalCurrentAmount(Double totalCurrentAmount) {
        this.totalCurrentAmount = Functions.getDouble3Decimal(totalCurrentAmount);
    }

    @Column(name = "deleted")
    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "processDressmaker")
    public List<ProcessDressmakerPurchaseDetail> getListProcessDressmakerPurchaseDetail() {
        return listProcessDressmakerPurchaseDetail;
    }

    public void setListProcessDressmakerPurchaseDetail(List<ProcessDressmakerPurchaseDetail> listProcessDressmakerPurchaseDetail) {
        this.listProcessDressmakerPurchaseDetail = listProcessDressmakerPurchaseDetail;
    }

    @Transient
    public String getDatas(){
        return "init date: "+initDate+" end date: "+endDate+" employee: "+employee.getFullName();
    }

}
